import React, {useEffect,useRef,useState} from 'react'
import {Card} from 'antd'
import {GridContent} from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table'
import moment from 'moment';
import {findDictionary,queryInternalPage} from "../../service";


const Internal = ({oid}) => {
  const [categoryType,setCategoryType] = useState([]);
  const [modeList,seModeList] = useState([]);

  useEffect(() => {
    findDictionary("CODE_RewardPunishMentType").then(res => {
      setCategoryType(res);
    });
    findDictionary("CODE_jiangchengfangshi").then(res => {
      seModeList(res);
    });
  }, []);

  const columns = [
    {
      title: '序号',
      render:(text,record,index)=>`${index+1}`,
      hideInSearch: true,
    },
    {
      title: '奖惩类别',
      hideInSearch: true,
      dataIndex: 'category',
      render: (text) => {
        return categoryType.find((item) => item.value === text)?.label;
      }
    },
    {
      title: '奖惩方式',
      hideInSearch: true,
      dataIndex: 'mode',
      render: (text) => {
        return modeList.find((item) => item.value === text)?.label;
      }
    },
    {
      title: '奖惩事由',
      hideInSearch: true,
      dataIndex: 'cause',
      ellipsis:true,
      width: '30%'
    },
    {
      title: '奖惩金额',
      hideInSearch: true,
      dataIndex: 'amount',
    },
    {
      title: '奖惩时间',
      dataIndex: 'jcTime',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM-DD') : '';
      },
    }
  ];


  return (
    <>
      <GridContent>
        <Card title="奖惩信息" style={{marginBottom: 24}} bordered={false}>
          <ProTable
            rowKey="id"
            search={false}
            options={false}
            request={(params) => queryInternalPage(oid)}
            columns={columns}
          />
        </Card>
      </GridContent>
    </>
  );
};
export default Internal;
